#include <iostream>
#include <vector>
#include <queue>
using namespace std;

struct Node
{
    int deepth = 0;
    queue<int> nums;
    vector<Node> sons;
    vector<int> been; 
    vector<int> beenxy;
    vector<int> beenyx;
};

int count1 = 0;
int n = 0;

void dfs(Node now)
{
    if(now.deepth < n)
    {
        for(int i = 0; i < now.sons.size(); i++)
        {
            Node son = now.sons[i];
            
            for(int j = 1; j <= n; j++)
            {
                if(son.been[j] == 1 || son.beenxy[son.deepth + 1 - j + 50] == 1
                || son.beenyx[(n - son.deepth) - j + 50] == 1)
                    continue;
                Node temp;
                temp.been = son.been;
                temp.beenxy = son.beenxy;
                temp.beenyx = son.beenyx;
                temp.deepth = son.deepth + 1;
                temp.nums = son.nums;
                temp.nums.push(j);
                temp.been[j] = 1;
                temp.beenxy[son.deepth + 1 - j + 50] = 1;
                temp.beenyx[(n - son.deepth) - j + 50] = 1;
                son.sons.push_back(temp);
            }

            dfs(son);
        }
    }else{
        count1 = count1 + 1;
        if(count1 <= 3)
        {
            while(!now.nums.empty())
            {
                int number = now.nums.front();
                now.nums.pop();
                cout << number << " ";
            }
            cout << endl;
        }
    }
}

int main()
{
    cin >> n;
    Node root;
    for(int i = 0; i <20; i++)
    {
        root.been.push_back(0);
    }
    for(int i = 0; i < 100; i++)
    {
        root.beenxy.push_back(0);
        root.beenyx.push_back(0);
    }
    for(int i = 1; i <= n; i++)
    {
        Node temp;
        temp.been = root.been;
        temp.beenxy = root.beenxy;
        temp.beenyx = root.beenyx;
        temp.deepth = 1;
        temp.nums.push(i);
        temp.been[i] = 1;
        temp.beenxy[temp.deepth - i + 50] = 1;
        temp.beenyx[(n - temp.deepth + 1) - i + 50] = 1; 
        root.sons.push_back(temp);
    }
    
    dfs(root);
    cout << count1;
}